﻿#include "Geometry.h"

using namespace DYGraphics;

static MeshPtr mesh;

MeshPtr Geometry::GetTriangle()
{
	if (mesh != nullptr) 
		return mesh;

	float positions[3][3] = 
	{
		{-0.5f, -0.5f, 0.0f},
		{ 0.5f, -0.5f, 0.0f},
		{ 0.0f,  0.5f, 0.0f},
	};

	float normals[3][3] = 
	{
		{ 0, 0, 1.0f },
		{ 0, 0, 1.0f },
		{ 0, 0, 1.0f },
	};

	float uvs[3][2] = 
	{
		{ 0, 0 },
		{ 1.0f, 0 },
		{ 0.5f, 1.0f },
	};

	unsigned int indices[3] =
	{
		0u, 1u, 2u,
	};

	Vertex* vertices = new Vertex[3];
	for (int i = 0; i < 3; i++)
	{
		vertices[i].position[0] = positions[i][0];
		vertices[i].position[1] = positions[i][1];
		vertices[i].position[2] = positions[i][2];
		vertices[i].normal[0] = normals[i][0];
		vertices[i].normal[1] = normals[i][1];
		vertices[i].normal[2] = normals[i][2];
		vertices[i].texcoord[0] = uvs[i][0];
		vertices[i].texcoord[1] = uvs[i][1];
	}

	mesh = std::make_shared<Mesh>();
	mesh->SetVertices(3, vertices);
	mesh->SetIndices(3, indices);
	return mesh;
}
